package com.sms.common;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * @desc Entity基类
 * @author WuJiangWu
 * @date 2018年7月21日上午1:41:43
 */
@MappedSuperclass
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler", "fieldHandler" })
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public abstract class BaseEntity implements Serializable {
    
	private static final long serialVersionUID = 1L;
    
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(updatable = false)
    protected Date createDate;// 创建日期
    
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    // @JsonIgnore
    protected Date updateDate;// 更新日期
    
    @JsonIgnore
    @Length(min = 1, max = 1)
    protected String delFlag; // 删除标记（0：正常；1：删除；）
    
    /**
     * 构造函数
     */
    public BaseEntity() {
        super();
        this.delFlag = "0";
    }
    
    /**
     * 新增之前
     */
    @PrePersist
    public void prePersist() {
        this.updateDate = new Date();
        this.createDate = this.updateDate;
    }
    
    /**
     * 修改之前
     */
    @PreUpdate
    public void preUpdate() {
        this.updateDate = new Date();
    }

    
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public Date getUpdateDate() {
		return updateDate;
	}
	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
	public String getDelFlag() {
		return delFlag;
	}
	public void setDelFlag(String delFlag) {
		this.delFlag = delFlag;
	}
    
}
